package com.guigu.service_user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.common_util.pojo.utils.Result;
import com.guigu.service_user.entity.TbAreas;
import com.guigu.service_user.entity.TbCities;
import com.guigu.service_user.mapper.TbCitiesMapper;
import com.guigu.service_user.service.ITbCitiesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 行政区域地州市信息表 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-07-09
 */
@Service
public class TbCitiesServiceImpl extends ServiceImpl<TbCitiesMapper, TbCities> implements ITbCitiesService {

    @Override
    public Result findPage(Map<String, Object> searchMap, Integer page, Integer size) {
        QueryWrapper<TbCities> wrapper = createExample(searchMap);
        //创建page对象
        Page<TbCities> pageAlbum = new Page<>(page,size);
        baseMapper.selectPage(pageAlbum,wrapper);
        return Result.ok().data("row",pageAlbum.getRecords()).data("total",pageAlbum.getTotal());
    }
    // 根据查询条件封装模块对象
    private QueryWrapper<TbCities> createExample(Map<String, Object> searchMap) {
        QueryWrapper<TbCities> wrapper = new QueryWrapper<>();
        if(searchMap!=null) {
            if(searchMap.get("cityid")!=null)
                wrapper.eq("cityid",searchMap.get("cityid"));
            if(searchMap.get("city")!=null && !"".equals(searchMap.get("city")))
                wrapper.like("city",searchMap.get("city"));
            if(searchMap.get("provinceid")!=null)
                wrapper.eq("provinceid",searchMap.get("provinceid"));
        }
        return wrapper;
    }
}
